import binaryTreeSearch.BinaryTreeSearch;
import demo1.HashBucket;
import demo1.HashBucket2;

import java.util.*;

class Student {
    private String id;

    public Student(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}

public class Test {

    // 统计元素个数
    public static void main(String[] args) {
        int[] arr = {1,1,2,3,4,2,3};
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < arr.length; i++) {
            if(!map.containsKey(arr[i])) {
                map.put(arr[i], 1);
            } else {
                map.put(arr[i], map.get(arr[i]) + 1);
            }
        }

        for(Map.Entry<Integer, Integer> entry: map.entrySet()) {
            System.out.println("key :" + entry.getKey() + " val: " + entry.getValue());
        }
    }

    // 去重
    public static void main6(String[] args) {
        int[] arr = {1,1,2,3,4,2,3};
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < arr.length; i++) {
            set.add(arr[i]);
        }
        System.out.println(set);
    }
    public static void main5(String[] args) {
        HashBucket2<Student, String> hashBucket = new HashBucket2<>();
        Student student1 = new Student("nihao");
        Student student2 = new Student("nihao");
        hashBucket.put(student1, "20");
        System.out.println(hashBucket.get(student2));
    }

    public static void main4(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(1,11);
        hashBucket.put(2,22);
        hashBucket.put(3,33);
        hashBucket.put(11,44);
        hashBucket.put(21,21);
        hashBucket.put(4,4);
        hashBucket.put(55,55);
        hashBucket.put(12,12);

        System.out.println(hashBucket.get(1));
        System.out.println(hashBucket.get(11));
        System.out.println(hashBucket.get(3));
        System.out.println(hashBucket.get(2));
    }

    public static void main3(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("12awdw");
        set.add("1231");
        set.add("1");

        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
    public static void main2(String[] args) {
        Map<String, Integer> map = new TreeMap<>();
        map.put("this", 3);
        map.put("the", 4);
        map.put("the", 5);

        System.out.println(map.keySet());

        System.out.println(map.getOrDefault("thisq", 0));
        System.out.println(map.get("this"));

        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        for(Map.Entry<String, Integer> entry : entrySet) {
            System.out.println("key: " + entry.getKey() + " value:" + entry.getValue());
        }
    }
    public static void main1(String[] args) {
        BinaryTreeSearch binaryTreeSearch = new BinaryTreeSearch();
        int[] arr = {5,12,3,2,11,15};
        for (int i = 0; i < arr.length; i++) {
            binaryTreeSearch.insert(arr[i]);
        }
        binaryTreeSearch.remove(2);
        binaryTreeSearch.remove(12);
        binaryTreeSearch.remove(5);
        System.out.println(binaryTreeSearch.search(14));
        System.out.println(binaryTreeSearch.search(11));


    }
}
